//
//  BluetoothAlertType.swift
//  DaRings
//
//  Created by 尹琼 on 2022/12/8.
//

import UIKit
import MYModule

public enum BluetoothAlertType: String {
    
    case heartRate = "com.moyoung.ring.heartRate"
    case sedentary = "com.moyoung.ring.sedentary"
    case lowPowerBettry = "com.moyoung.ring.lowPowerBettry"
    
    // GPS 锻炼目标达成
    case gpsTrainingGoal = "com.moyoung.ring.gpsTrainingGoal"
    // 锻炼目标达成
    case trainingGoal = "com.moyoung.ring.trainingGoal"
    // 日常步数达成
    case activityStepGoal = "com.moyoung.ring.activityStepGoal"
    // 日常卡路里达成
    case activityCaloriesGoal = "com.moyoung.ring.activityCaloriesGoal"
    // 日常锻炼时长达成
    case activityTimeGoal = "com.moyoung.ring.activityTimeGoal"
    
    public var imageName: String {
        
        switch self {
        case .heartRate:
            return "ic_reminder_hr"
        case .sedentary:
            return "ic_reminder_health"
        case .lowPowerBettry:
            return "ic_reminder_low_battery"
        case .trainingGoal:
            return "ic_reminder_training_gps"
        case .activityStepGoal:
            return "ic_reminder_training_gps"
        case .activityCaloriesGoal:
            return "ic_reminder_training_gps"
        case .activityTimeGoal:
            return "ic_reminder_training_gps"
        case .gpsTrainingGoal:
            return "ic_reminder_training"
            
        }
    }
    
    public var title: String {
        
        switch self {
        case .heartRate:
            return "dialog_high_heart_rate_title".language
        case .sedentary:
            return "dialog_sedentary_reminder_title".language
        case .lowPowerBettry:
            return "dialog_low_battery_title".language
        case .trainingGoal:
            return "training_goal_reached".language
        case .activityStepGoal:
            return "dialog_daily_goals_title".language
        case .activityCaloriesGoal:
            return "dialog_daily_goals_title".language
        case .activityTimeGoal:
            return "dialog_daily_goals_title".language
        case .gpsTrainingGoal:
            return "training_goal_reached".language
        }
    }
    
    public func content(value: String) ->String {
        
        switch self {
        case .heartRate:
            return "dialog_high_heart_rate_content".language(with: [value])
            
        case .sedentary:
            return "dialog_sedentary_reminder_content".language
            
        case .lowPowerBettry:
            return "dialog_low_battery_content".language(with: [value])
            
        case .trainingGoal:
            return ""
           
        case .activityStepGoal:
            let value_unit = "\(value) \(unit)"
            return "dialog_daily_goals_content".language(with: [value_unit])
            
        case .activityCaloriesGoal:
            let value_unit = "\(value) \(unit)"
            return "dialog_daily_goals_content".language(with: [value_unit])
            
        case .activityTimeGoal:
            let value_unit = "\(value) \(unit)"
            return "dialog_daily_goals_content".language(with: [value_unit])
            
        case .gpsTrainingGoal:
            return ""
            
        }
        
    }
    
    public func attributedString(value: String) -> NSMutableAttributedString {
        
        let str = self.content(value: value)
        
        let attriText = str.toAttributed.font(Fonts.systemFont(ofSize: 14.0))
            .foregroundColor(UIColor.assist_A9A9A9)
            .paragraph {
                $0.lineSpacing = 5.0
                $0.alignment = .center
            }.rawValue
        
        if !value.isEmpty {
            let range = (str as NSString).range(of: value)
            attriText.addAttributes([
                .font: self.valueFont,
                .foregroundColor: self.valueColor], range: range)
            
        }
        
        return attriText
        
    }
    
    public var unit: String {
        
        switch self {
       
        case .activityStepGoal:
            return "unit_step".language
        case .activityCaloriesGoal:
            return "unit_calorie".language
        case .activityTimeGoal:
            return "unit_minute".language
            
        default:
            return ""
        }
    }
    
    public var valueFont: UIFont {
        
        switch self {
       
        case .activityStepGoal, .activityCaloriesGoal, .activityTimeGoal:
            return Fonts.boldSystemFont(ofSize: 15.0)
        default:
            return Fonts.systemFont(ofSize: 14.0)
            
        }
    }
    
    public var valueColor: UIColor {
        
        switch self {
        case .activityStepGoal, .activityCaloriesGoal, .activityTimeGoal:
            return tintColor
        default:
            return UIColor.assist_A9A9A9
        }
        
    }
    
    public var tintColor: UIColor {
        
        switch self {
       
        case .activityStepGoal, .activityCaloriesGoal, .activityTimeGoal:
            return UIColor.GPSTraining.theme
    
        case .heartRate:
            return UIColor.HeartRate.theme
        case .sedentary:
            return UIColor.Step.theme
        case .lowPowerBettry:
            return UIColor.Training.theme
        case .gpsTrainingGoal:
            return UIColor.Training.theme
        case .trainingGoal:
            return UIColor.GPSTraining.theme
        }
        
    }
    
    
    public func notifactionContent(value: String) -> UNMutableNotificationContent {
        
        let content = UNMutableNotificationContent()
        
        content.title = self.title
        content.body = self.content(value: value)
       
        return content
        
    }
}
